require "scripts.少年光头.UiHelper.UiHelper"
require "scripts.少年光头.Helper.Set"
require "scripts.少年光头.DiyItem.diyItem"
require "scripts.少年光头.Helper.deepcopy"
require "scripts.少年光头.GTBar.GTBar"
require "scripts.少年光头.Helper.randomAttr"

Set.heroReborn(0)
DiyItems = diyitem:new()
Set.Hp()

hsync.onSend(
    "发送",
    function(syncData)
        print_mbr(hplayer.getName(syncData.triggerPlayer))
        print_mbr(syncData.triggerData)
        print_mbr(syncData.triggerPlayer)
        hunit.create(
            {
                whichPlayer = hplayer.players[1],
                id = hslk.n2i("少年光头天选勇者"),
                x = 0,
                y = 200,
                isOpenSlot = true
            }
        )
    end
)
---添加diy物品
for index, value in ipairs(AllItems) do
    local itemid =
        hitem.create(
        {
            id = hslk.n2i(value.Name),
            x = index * 100,
            y = 200,
            charges = value.uses or 1
        }
    )
    ---print_mbr(itemid)

    DiyItems:add(itemid)
    DiyItems:Skill(
        itemid,
        function(v)
            print_mbr(v)
            DiyItems:randomAttr(itemid)
        end
    )
    --print_mbr(HSLK_SYNTHESIS)
end

---添加diy物品
for index, value in ipairs(AllItems) do
    local itemid =
        hitem.create(
        {
            id = hslk.n2i(value.Name),
            x = index * 100,
            y = 300,
            charges = value.uses or 1
        }
    )

    DiyItems:add(itemid)
    DiyItems:Skill(
        itemid,
        function(v)
            DiyItems:randomAttr(itemid)
        end
    )
    --print_mbr(HSLK_SYNTHESIS)
end
---添加diy物品
for index, value in ipairs(AllItems) do
    local itemid =
        hitem.create(
        {
            id = hslk.n2i(value.Name),
            x = index * 100,
            y = 400,
            charges = value.uses or 1
        }
    )

    DiyItems:add(itemid)
    DiyItems:Skill(
        itemid,
        function(v)
            DiyItems:randomAttr(itemid)
        end
    )
    --print_mbr(HSLK_SYNTHESIS)
end

-- ---添加diy物品
-- for index, value in ipairs(AllItems) do
--     local itemid =
--         hitem.create(
--         {
--             id = hslk.n2i(value.Name),
--             x = index * 100,
--             y = 300
--         }
--     )

--     DiyItems:add(itemid)
--     DiyItems:Skill(itemid,function(v)
--         echo("22222222222222222222222222222222222222222222222")

--     end)
--     --print_mbr(HSLK_SYNTHESIS)
-- end
local u =
    hunit.create(
    {
        whichPlayer = hplayer.players[1],
        id = hslk.n2i("少年光头天选勇者"),
        x = 0,
        y = 200,
        isOpenSlot = true
    }
)
print_mbr(u)

--模拟血条
GTBar():hpSetPosition(u)

hattr.set(u, 0, {attack = "+1000"})
hattr.set(u, 20, {knocking_odds = "+50"})
hattr.set(u, 15, {defend = "-5"})
-- htime.setInterval(
--     1,
--     function(curTimer)
--         --模拟血条
--         GTBar():hpSetPosition(
--             hunit.create(
--                 {
--                     whichPlayer = hplayer.players[11],
--                     id = hslk.n2i("财神"),
--                     x = 0,
--                     y = 200,
--                     isOpenSlot = true
--                 }
--             )
--         )
--     end
-- )

--物品栏tip
UiHelper.itemtip("物品栏"):InventoryItemTipOpen(DiyItems)

--鼠标指定物品TIP
UiHelper.itemtip("鼠标"):MouseItemTipOpen(DiyItems)

UiHelper.unittip():MouseUnintOpen()
---UiHelper.backdrop({fdfName="sysItemTip"}):dfsize(0.1,0.1):dfpointp(0, 0,nil,FRAME_ALIGN_CENTER,FRAME_ALIGN_CENTER)

-- UiHelper.button(
--     {
--         relation = hdzui.origin.game(),
--         align = FRAME_ALIGN_CENTER,
--         alignRelation = FRAME_ALIGN_CENTER,
--         x = 0,
--         text="1231",
--         btTextAlign="z",
--         y = 0,
--         w = 0.02,
--         h = 0.02,
--         click = function()
--             if hplayer.loc() == hplayer.loc() then
--                 hsync.send("发送", "发送")
--             else
--             end
--         end
--     }
-- )
-- local xxxx= UiHelper.frame(
--     {
--         align = FRAME_ALIGN_CENTER,
--         alignRelation = FRAME_ALIGN_CENTER,
--         x = 0,
--         y = 0,

--         fdfType = "TEXTBUTTON",
--         fdfName = "StandardButtonTemplate"
--     }
-- )
-- hjapi.DzFrameSetText(xxxx.frameId, "123123123")
-- local b1= UiHelper.backdrop(

-- ):dfsize(0.1,0.01):dfpointp(0, 0, hdzui.origin.game(), FRAME_ALIGN_CENTER, FRAME_ALIGN_CENTER)

-- UiHelper.label(
-- ):dfpointp(0, 0,b1.frameId, FRAME_ALIGN_CENTER, FRAME_ALIGN_CENTER):dftext("b1")

-- local b2= UiHelper.backdrop(

-- ):dfsize(0.1,0.01):dfsize(0.1,0.01):dfClearAllPoints():dfpoint(0,0,FRAME_ALIGN_LEFT_BOTTOM,b1.frameId,FRAME_ALIGN_LEFT_TOP):dfpoint(0,0,FRAME_ALIGN_RIGHT_BOTTOM,b1.frameId,FRAME_ALIGN_RIGHT_TOP)

-- -- hjapi.DzFrameSetPoint(b2.frameId, FRAME_ALIGN_LEFT_BOTTOM, b1.frameId, FRAME_ALIGN_LEFT_TOP, 0, 0)
-- -- hjapi.DzFrameSetPoint(b2.frameId, FRAME_ALIGN_RIGHT_BOTTOM, b1.frameId, FRAME_ALIGN_RIGHT_TOP, 0, 0)

-- UiHelper.label(
-- ):dfpointp(0, 0,b2.frameId, FRAME_ALIGN_CENTER, FRAME_ALIGN_CENTER):dftext("b2")

for i = 1, 10, 1 do
    local tim =
        htime.setTimeout(
        i * 10,
        function(curTimer)
        end
    )
    UiHelper.TimeTip("计时器" .. i .. ":", tim)
end

-- print_mbr(BigNum.mt.add( "1" , "1" ))

local rc = hrect.create(0, 0, 500, 500, "区域")

---henv.random(rc,"poor",false,false)
local ground = HL_ID.env.ground.summer
local doodad = {
    HL_ID.env.doodad.treeSummer
}
local unit = {}

-- henv.CreateDestructable(doodad[1][1], hrect.getMinX(rc), hrect.getMinY(rc), 0, 1)
-- henv.CreateDestructable(doodad[1][1], hrect.getMaxX(rc), hrect.getMaxY(rc), 0, 1)
local a = 0

-- htime.setInterval(
--     0.03,
--     function(curTimer)
--         if a>=360 then
--             curTimer.destroy()
--         end
--         ---local d= math.polarProjection(0,0,500,a)
--         --henv.SetTerrainType(d.x, d.y, ground)
--         local x= hrect.getMinX(rc)
--         local y= hrect.getMinY(rc)
--         henv.CreateDestructable(doodad[1][1], x, y, 0, 1)
--     end
-- )

-- local x = 0

-- print_mbr(henv.GetTerrainType(0,0))

-- henv.build(rc, "树林", false, false, ground, doodad, unit)
-- henv.build(rc, "树林", false, false, ground, doodad, unit)
-- henv.build(rc, "树林", false, false, ground, doodad, unit)
-- henv.build(rc, "树林", false, false, ground, doodad, unit)
-- hweather.create({x = 0, y = 0, w = 0, h = 0, whichRect = hrect.world(), type = hweather.sun, during = 0})

---hweather.create({x = 0, y = 0, w = 0, h = 0, whichRect = hrect.world(), type = hweather.sun, during = 0})
-- hweather.create({x = 0, y = 0, w = 0, h = 0, whichRect = hrect.world(), type = hweather.sun, during = 0})
-- hweather.create({x = 0, y = 0, w = 0, h = 0, whichRect = hrect.world(), type = hweather.sun, during = 0})
-- hweather.create({x = 0, y = 0, w = 0, h = 0, whichRect = hrect.world(), type = hweather.sun, during = 0})
-- hweather.create({x = 0, y = 0, w = 0, h = 0, whichRect = hrect.world(), type = hweather.sun, during = 0})
---TriggerRegisterGameStateEvent

-- require "scripts.少年光头.Helper.system.surroundings"
-- ---surroundings(1)
-- require "scripts.少年光头.Helper.hlua.himage"

require "scripts.少年光头.Helper.system.monsterZone"
---少年光头天选勇者
monsterZone()
monsterZone.Monsters["少年光头天选勇者"] = {
    ---怪物名字
    Name = "少年光头天选勇者",
    ---怪物创建事件 精英怪事件
    CreateEvent = function(uid)
        print_mbr("创建怪物事件")
    end,
    ---自定义死亡事件 收益事件等
    DeadEvent = function(data)
        print_mbr(data)
    end,
    ---Ai
    Ai = {}
}

monsterZone:CreateArea(
    0,
    0,
    500,
    500,
    "刷怪",
    11,
    function(Monsters)
        print_mbr("怪物以清空")
    end,
    function(Monsters)
        print_mbr("怪物生成完成")
    end,
    3,
    1,
    0,
    2
)
monsterZone:CreateArea(
    500,
    500,
    500,
    500,
    "刷怪2",
    11,
    function(Monsters)
        print_mbr("怪物以清空")
    end,
    function(Monsters)
        print_mbr("怪物生成完成")
    end,
    3,
    1,
    0,
    2
)

monsterZone:OpenAreaMonsters("刷怪")
monsterZone:OpenAreaMonsters("刷怪2")
monsterZone:AddAreaMonsterNames("刷怪", "少年光头天选勇者")
monsterZone:AddAreaMonsterNames("刷怪2", "少年光头天选勇者")
monsterZone:AreaMonstersFor("刷怪")
monsterZone:AreaMonstersTime("刷怪2")




---r = 5 theta = t*3600 z =(sin(3.5*theta-90))+24*t

-- function a()

-- end
